package com.fqdf.framework.android.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

/**
 * @author 张枭
 *         date 2017/4/6
 * @version V1.0
 */
public abstract class CommonMyAdapter<T> extends BaseMyAdapter<T> {

    private int layoutRes;

    public CommonMyAdapter(Context context, int res) {
        super(context);
        layoutRes = res;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final CommonViewHolder vh = getViewHodler(position, convertView, parent);
        convert(vh, getItem(position));
        return vh.getConvertView();
    }

    // 获取ViewHodler
    public CommonViewHolder getViewHodler(int position, View convertView, ViewGroup parent) {

        return CommonViewHolder.getViewHolder(getContext(), convertView, parent, layoutRes,
                position);
    }

    // 提供给外部填充实际的显示数据，以及可以一些其他的操作，如：隐藏＝＝
    public abstract void convert(CommonViewHolder vh, T item);
}
